package service

import "gadmin/model"

func CreateTable(table model.Table) (err error) {
	result := model.DB.Create(&table)
	return result.Error
}

func GetTable() (tables []model.Table, err error) {
	result := model.DB.Preload("Columns").Find(&tables)
	if result.Error != nil {
		return nil, result.Error
	}
	return tables, nil
}

func DeleteTable(id int64) (err error) {
	result := model.DB.Delete(&model.Table{}, id)
	if result.Error != nil {
		return result.Error
	}
	return nil
}

func UpdateTable() {
}

func CreateColumn(tableID uint, _type string, _title string, _dataIndex string, _order uint) (column model.Column, err error) {
	column = model.Column{TableID: tableID, Type: _type, Title: _title, DataIndex: _dataIndex, Order: _order}
	result := model.DB.Create(&column)
	return column, result.Error
}

func DeleteColumn() {
}

func UpdateColumn() {
}

func FindColumn() {
}
